<include file="Public/min-header"/>

<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <nav class="navbar navbar-default">
                            <div class="pull-right navbar-form">
                                <label><a class="btn btn-block btn-primary" href="javascript:void(0)" id="add-menu"
                                          data-url="">添加导航菜单</a></label>
                            </div>
                        </nav>
                    </div>
                    <div class="box-body">
                        <div class="row">
                            <div class="col-sm-12">
                                <table id="list-table" class="table table-bordered table-striped dataTable" role="grid"
                                       aria-describedby="example1_info">
                                    <thead>
                                    <tr role="row">
                                        <th>ID</th>
                                        <th class="sorting" tabindex="0" aria-controls="example1">标题</th>
                                        <th class="sorting" tabindex="0" aria-controls="example1">排序</th>
                                        <th class="sorting" tabindex="0" aria-controls="example1">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <foreach name="tree" item="v">
                                        <tr id="mod-{$v.mod_id}">
                                            <td>{$v.mod_id}</td>
                                            <td style="text-align:left;">&nbsp;&nbsp;<strong>{$v.title}</strong></td>
                                            <td>
                                                <input type="text" name="orderby[{$v.mod_id}]" value="{$v.orderby}"
                                                       class="input-sm"
                                                       onkeyup="this.value=this.value.replace(/[^\d]/g,'')"
                                                       onpaste="this.value=this.value.replace(/[^\d]/g,'')"
                                                       onchange="updateSort('system_module','mod_id','{$v.mod_id}','orderby',this)"/>
                                            </td>
                                            <td>
                                                <a href="javascript:void(0)"
                                                   data-url="{:U('Admin/System/create_menu',array('mod_id'=>$v[mod_id],'action'=>'add'))}"
                                                   class="btn btn-primary create-sub-menu">添加菜单</a>
                                                <a href="javascript:void(0)"
                                                   data-url="{:U('Admin/System/create_menu',array('mod_id'=>$v[mod_id],'action'=>'edit'))}"
                                                   class="btn btn-info create-sub-menu">编辑</a>
                                                <a href="javascript:void(0)" data-url="{:U('Admin/System/menuSave')}"
                                                   data-id="{$v.mod_id}" class="btn btn-danger del-sub-menu">删除</a>
                                            </td>
                                        </tr>
                                        <foreach name="v.menu" item="vv">
                                            <tr id="mod-{$vv.mod_id}">
                                                <td>{$vv.mod_id}</td>
                                                <td style="text-align:left;">
                                                    &nbsp;&nbsp;|----<strong>{$vv.title}</strong></td>
                                                <td><input type="text" name="orderby[{$vv.mod_id}]"
                                                           value="{$vv.orderby}" class="input-sm"
                                                           onchange="updateSort(this,{$vv.mod_id})"/></td>
                                                <td>
                                                    <a href="javascript:void(0)" class="btn btn-default model-edit"
                                                       data-url="{:U('Admin/System/ctl_detail',array('mod_id'=>$vv[mod_id]))}">控制模块</a>
                                                    <a href="javascript:void(0)" class="btn btn-info create-sub-menu"
                                                       data-url="{:U('System/create_menu',array('action'=>'edit','mod_id'=>$vv[mod_id]))}">编辑</a>
                                                    <a href="javascript:void(0)"
                                                       data-url="{:U('Admin/System/menuSave')}" data-id="{$vv.mod_id}"
                                                       class="btn btn-danger del-sub-menu">删除</a>
                                                </td>
                                            </tr>
                                        </foreach>
                                    </foreach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<script>
    $('#add-menu').click(function () {
        layer.open({
            type: 2,
            title: '添加导航',
            shadeClose: true,
            shade: 0.8,
            area: ['450px', '320px'],
            content: "{:U('Admin/System/create_menu')}",
        });
    });

    //管理菜单
    $('.create-sub-menu').click(function () {
        var url = $(this).attr('data-url');
        layer.open({
            type: 2,
            title: '管理菜单',
            shadeClose: true,
            shade: 0.8,
            area: ['450px', '320px'],
            content: url,
        });
    });

    //控制模块
    $('.model-edit').click(function () {
        var url = $(this).attr('data-url');
        layer.open({
            type: 2,
            title: '管理模块',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '70%'],
            content: url,
        });
    });

    //删除菜单
    $('.del-sub-menu').click(function () {
        var url = $(this).attr('data-url') + '/' + Math.random();
        var mod_id = $(this).attr('data-id');
        layer.confirm('删除菜单要慎重哦', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: {mod_id: mod_id, action: 'del'},
                success: function (data) {
                    if (data.stat == 'ok') {
                        layer.msg('删除成功', {icon: 1});
                        $('#mod-' + mod_id).remove();
                    } else {
                        layer.msg(data.msg, {icon: 3});
                    }
                }
            });
        }, function () {
            layer.close();
        });
    });


    //回调函数
    function call_back(msg) {
        if (msg > 0) {
            //layer.alert('操作成功');
            layer.msg('操作成功', {icon: 1});
            layer.closeAll('iframe');
            window.location.reload();
        } else {
            //layer.alert('操作失败');
            layer.msg('操作失败', {icon: 3});
            layer.closeAll('iframe');
        }
    }
</script>

</body>
</html>